package com.cskaoyan.servlet;

import com.cskaoyan.bean.vo.GoodsVo;
import com.cskaoyan.service.GroupGoodsService;
import com.cskaoyan.service.GroupGoodsServiceImpl;
import com.cskaoyan.util.JacksonUtil;
import com.cskaoyan.util.ResponseUtil;
import com.cskaoyan.util.URIUtil;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/goods/update")
public class GroupGoodsUpdateServlet extends WdBaseServlet {


    private GroupGoodsService groupGoodsService = new GroupGoodsServiceImpl();


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String operation = URIUtil.getOperation(this.getClass(), request);

        update(request,response);


    }

    // /admin/goods/create
    private void update(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String jsonStr = request.getReader().readLine();
        GoodsVo goodsVo = JacksonUtil.read(jsonStr, GoodsVo.class);
        ResponseUtil.responseJson(response, groupGoodsService.update(goodsVo));
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        doGet(req, resp);
    }
}

